package com.iocup.keybastion.sso.core;


import com.iocup.keybastion.sso.ClientElementProvider;
import com.iocup.keybastion.sso.ClientService;
import com.iocup.keybastion.sso.config.Client;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author xyjxust
 * @create 2023/2/2 10:06
 **/
public class ClientServiceImpl implements ClientService {

    private static final Map<String, Client> CLIENT_MAP = new HashMap<>();

    public ClientServiceImpl(List<ClientElementProvider> clientElementProviders) {
        clientElementProviders.forEach(clientElementProvider -> clientElementProvider.getAll().forEach(client -> CLIENT_MAP.put(client.getClientId(), client)));
    }

    @Override
    public Client get(String clientId) {
        return CLIENT_MAP.get(clientId);
    }
}
